package com.cicigodd.brick.plug.system.dict.controller;

import com.cicigodd.brick.plug.annotation.repeatsubmit.RepeatSubmit;
import com.cicigodd.brick.plug.annotation.resource.DeleteResource;
import com.cicigodd.brick.plug.annotation.resource.GetResource;
import com.cicigodd.brick.plug.annotation.resource.PostResource;
import com.cicigodd.brick.plug.annotation.resource.PutResource;
import com.cicigodd.brick.plug.common.response.PageResult;
import com.cicigodd.brick.plug.common.response.Result;
import com.cicigodd.brick.plug.common.response.ResultGenerator;
import com.cicigodd.brick.plug.system.dict.request.*;
import com.cicigodd.brick.plug.system.dict.response.SysDictDetailResponse;
import com.cicigodd.brick.plug.system.dict.response.SysDictListResponse;
import com.cicigodd.brick.plug.system.dict.service.SysDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


@Api(tags = "系统字典类型")
@RestController
public class SysDictController {

    @Resource
    private SysDictService sysDictService;

    @RepeatSubmit
    @ApiOperation(value = "系统字典类型添加", notes = "系统字典类型添加")
    @PostResource(name = "系统字典类型添加", path = "/sysDict/add")
    public Result add(@RequestBody @Validated SysDictAddRequest sysDictAddRequest) {
        sysDictService.add(sysDictAddRequest);
        return ResultGenerator.successResult();
    }


    @ApiOperation(value = "系统字典类型删除", notes = "根据id删除")
    @DeleteResource(name = "系统字典类型删除", path = "/sysDict/delete")
    public Result delete(@Validated SysDictDeleteRequest sysDictDeleteRequest) {
        sysDictService.delete(sysDictDeleteRequest);
        return ResultGenerator.successResult();
    }


    @ApiOperation(value = "系统字典类型编辑", notes = "系统字典类型编辑")
    @PutResource(name = "系统字典类型编辑", path = "/sysDict/edit")
    public Result edit(@RequestBody @Validated SysDictEditRequest sysDictEditRequest) {
        sysDictService.edit(sysDictEditRequest);
        return ResultGenerator.successResult();
    }


    @ApiOperation(value = "系统字典类型详情", notes = "根据id查询")
    @GetResource(name = "系统字典类型详情", path = "/sysDict/detail")
    public Result<SysDictDetailResponse> detail(SysDictDetailRequest sysDictDetailRequest) {
        SysDictDetailResponse detail = sysDictService.detail(sysDictDetailRequest);
        return ResultGenerator.successResult(detail);
    }


    @ApiOperation(value = "系统字典类型分页列表", notes = "系统字典类型分页列表")
    @GetResource(name = "系统字典类型分页列表", path = "/sysDict/list")
    public Result<PageResult<SysDictListResponse>> list(SysDictListRequest sysDictListRequest) {
        PageResult<SysDictListResponse> pageList =  sysDictService.list(sysDictListRequest);
        return ResultGenerator.successResult(pageList);
    }

    @ApiOperation(value = "系统字典类型列表", notes = "系统字典类型列表")
    @GetResource(name = "系统字典类型列表", path = "/sysDict/listAll")
    public Result<List<SysDictListResponse>> listAll(SysDictListRequest sysDictListRequest) {
        List<SysDictListResponse> pageList =  sysDictService.listAll(sysDictListRequest);
        return ResultGenerator.successResult(pageList);
    }
}
